package com.xncoding.starter.configure;

import com.xncoding.starter.inter.Reading01;
import com.xncoding.starter.properties.ReadingProperties01;
import com.xncoding.starter.service.ReadingService01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(ReadingProperties01.class)
public class ReadingSelector {
    @Autowired
    private ReadingProperties01 readingConfig01;

    // 当SpringIOC容器中不存在Reading实现时，才往Spring中初始化ReadingService作为Reading接口的实现
    @Bean
    @ConditionalOnMissingBean(Reading01.class)
    public Reading01 readingService01() {
        return new ReadingService01(this.readingConfig01);
    }

}